package com.zclcs.model;

import java.io.Serializable;

import com.zclcs.enums.CoreRetCodeEnum;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一返回对象
 *
 * @param <T>
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DataRet<T> implements Serializable {

	private static final long serialVersionUID = 2334429216612004113L;

	// 错误编码,只有错误时候返回
	private Integer code = CoreRetCodeEnum.RET_CODE_20000.getRetErrCode();
	// 处理结果信息
	private String message = CoreRetCodeEnum.RET_CODE_20000.getRetErrMessage();
	// 返回结果
	private T data;

	// 返回结果状态
	public DataRet(Integer code, String message) {
		this.code = code;
		this.message = message;
	}

	public DataRet(T data) {
		this.data = data;
	}

	// 处理结果是否正常，异常时请看异常码
	public boolean isSuccess() {
		return code == null || CoreRetCodeEnum.RET_CODE_20000.getRetErrCode().equals(code);
	}

}
